import { get, post, del } from '@/utils/request'
import type { ArticleDetail, CommentRes } from '@/types/data'

enum API {
  getArticleInfo = '/articles/', //获取文章详情
  getCommentList = '/comments', //获取文章平路
  updateLinkings = '/article/likings', //更新点赞
  updateCollections = '/article/collections' //更新收藏
}

export default class DataServe {
  // 获取文章详情
  static getArticleInfo(data: string) {
    return get<ArticleDetail>(API.getArticleInfo + data)
  }
  // 获取文章品论
  static getCommentList(data: { type: string; source: string; offset?: string }) {
    return get<CommentRes>(API.getCommentList, { params: data })
  }
  // 更新点赞
  static sendLinkings(data: string) {
    return post(API.updateLinkings, { target: data })
  }
  // 取消点赞
  static cancelLinkings(data: string) {
    return del(API.updateLinkings + '/' + data)
  }
  //收藏
  static sendCollections(data: string) {
    return post(API.updateCollections, { target: data })
  }
  //取消收藏
  static cancenCollections(data: string) {
    return del(API.updateCollections + '/' + data)
  }
}
